<?php
/*
@ Last (Google|Yahoo|Msn)ed Script
@ This script used to determine when was the last bot visited a page
@ Script ByPHP.NET - Developer - 2006 ©
*/

$useragent  = $_SERVER['HTTP_USER_AGENT'];
$today      = date("F j, Y");

if(eregi("Googlebot",$useragent) or strstr($useragent, 'Googlebot'))
{
	if ($_SERVER['QUERY_STRING'] != "")
	{
		$url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
		$insert = $DB->sql_query("INSERT INTO " . $db_prefix . "online (id,username,logged,user_ip,user_location) VALUES('NULL','" . $SF->SafeSQL($name) . "','" . $now . "','" . $ip . "','" . $u_location . "')");
	}
	else
	{
		$url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
		$DB->sql_query("DELETE FROM " . $db_prefix . "online WHERE username='".$name."'");
	}
	$name = 'Googled';
	$result = $DB->sql_query("INSERT INTO " . $db_prefix . "spider (url,date,agent,name) VALUES ('$url','$today','$useragent','$name')");

}

if(eregi("Yahoo! Slurp",$useragent) or strstr($useragent, 'Yahoo! Slurp'))
{
	if ($_SERVER['QUERY_STRING'] != "")
	{
		$url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
		$insert = $DB->sql_query("INSERT INTO " . $db_prefix . "online (id,username,logged,user_ip,user_location) VALUES('NULL','" . $SF->SafeSQL($name) . "','" . $now . "','" . $ip . "','" . $u_location . "')");
	}
	else
	{
		$url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
		$DB->sql_query("DELETE FROM " . $db_prefix . "online WHERE username='".$name."'");
	}
	$name = 'Yahood';
	$result = $DB->sql_query("INSERT INTO " . $db_prefix . "spider (url,date,agent,name) VALUES ('$url','$today','$useragent','$name')");

}

if(eregi("msnbot",$useragent) or strstr($useragent, 'msnbot'))
{
	if ($_SERVER['QUERY_STRING'] != "") 
	{
		$url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
		$insert = $DB->sql_query("INSERT INTO " . $db_prefix . "online (id,username,logged,user_ip,user_location) VALUES('NULL','" . $SF->SafeSQL($name) . "','" . $now . "','" . $ip . "','" . $u_location . "')");
	}
	else
	{
		$url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];	
		$DB->sql_query("DELETE FROM " . $db_prefix . "online WHERE username='".$name."'");
	}
	$name = 'Msned';
	$result = $DB->sql_query("INSERT INTO " . $db_prefix . "spider (url,date,agent,name) VALUES ('$url','$today','$useragent','$name')");

}
?>